package se.wangs.command;

import org.junit.Test;
import se.wangs.command.concretecommand.GarageDoorOpenCommand;
import se.wangs.command.concretecommand.LightOnCommand;
import se.wangs.command.invoker.SimpleRemoteController;
import se.wangs.command.executor.GarageDoor;
import se.wangs.command.executor.Light;

/**
 * * -- coding: UTF-8 -- *
 *
 * @author wangs
 * @date 2023/12/14 15:45
 * @description 测试文件
 */
public class SimpleRemoteControllerTest {
    // 1.声明控制器
    private SimpleRemoteController remoteController = new SimpleRemoteController();

    @Test
    public void lightCommandTest() {
        // 2.声明一个执行者，该执行者执行命令
        Light light = new Light();
        // 3.执行者与执行开关绑定
        Command lightOnCommand = new LightOnCommand(light);
        // 4.控制器与开关绑定
        remoteController.setCommand(lightOnCommand);
        remoteController.buttonWasPressed();
    }

    @Test
    public void garageDoorCommandTest() {
        // 2.声明命令执行者
        GarageDoor garageDoor = new GarageDoor();
        // 3.执行者与开关绑定
        Command garageDoorOpenCommand = new GarageDoorOpenCommand(garageDoor);
        // 4.开关与控制器绑定
        remoteController.setCommand(garageDoorOpenCommand);
        // 5.执行命令（在外部看来，执行命令的操作都是一致的）
        remoteController.buttonWasPressed();
    }
}
